<template>
	<view class="attbox">
		<image class="banter" src="../../static/imges/details1.png" mode=""></image>
		<view class="bold">
			<text style="line-height: 85rpx;">+86</text>
			<text class="butde">丨</text>
			<input class="boot" type="number" maxlength="11" v-model="phone" value="" placeholder="请输入手机号" />
		</view>
		<view class="bold" style="top: 330rpx;">
			<input class="boot" type="number" maxlength="6" v-model="inputVeCode" value="" placeholder="请输入验证码" />
			<view size="mini" @click="getCode()" v-if="authCode" class="botteer">获取验证码</view>
			<view size="mini" class="botteer" v-if="!authCode">{{ authTime }}S</view>

		</view>
		<view class="box1" @click="login">
			同意协议并登陆
		</view>
		<view class="box5">
			<text>已阅读并同意我们的</text>
			<text class="bue" @click="User">《用户协议》</text>
			<text>和</text>
			<text class="bue" @click="Privacy">《隐私政策》</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone: '',
				inputVeCode: '',
				authTime: 0,
				authCode: true,
				lest:[]
			}
		},
		onLoad() {
			
		},
		methods: {
			getHelloInof(){
			},
			reate(){
				this.getHelloInof()
			},
			getCode() {
				uni.request({
				    url: 'http://home.shengdaosoft.com/public/index.php/api/Sms/sendMessage', //仅为示例，并非真实接口地址。
				    data: {
						phone:this.phone
				    },
					method:'POST',	
					header: { 'content-type': 'application/x-www-form-urlencoded', },
				    success: (res) => {
				        console.log(res,"验证码");
				        this.text = 'request success';
				    }
				});
				let checkInputPhone = this.checkInputPhone()
				if (!checkInputPhone) {
					return
				}
				this.authTime = 3;
				this.authCode = false;
				this.btnShow = false;
				var sendTimer = setInterval(() => {
					this.authTime--;
					if (this.authTime <= 0) {
						this.authCode = true;
						clearInterval(sendTimer);
					}
				}, 1000);
			},
			
			login() {
				uni.request({
				    url: 'http://home.shengdaosoft.com/public/index.php/api/Login/Login', //仅为示例，并非真实接口地址。
				    data: {
						portrait:"https://dashenliaohangzhou.oss-cn-hangzhou.aliyuncs.com/long/jicu/20210427/16195095086087c10414c45.png",
						phone:this.phone,
						scene:this.inputVeCode
				    },
					method:'POST',
					header: { 'content-type': 'application/x-www-form-urlencoded', },
				    success: (res) => {
				        console.log(res,"用户注册登录");
				        this.text = 'request success';
						if(res.data.code==1){
							uni.reLaunch({
							    url: `/pages/My/My`
							});
							uni.setStorageSync('userId', res.data.data.id);
							uni.setStorage({
								key: 'id',
								data: res.data.data.id,
								success: function () {
									console.log('success');
								}
							});
						}else{
							uni.showToast({
								title: '登录失败',
								duration: 2000,
								icon: 'none'
							});
						}
				    }
				});
				let checkInputPhone = this.checkInputPhone()
				if (!checkInputPhone) {
					return
				}
				if (this.inputVeCode == '') {
					uni.showToast({
						title: '验证码不能为空',
						duration: 2000,
						icon: 'none'
					});
				}
				uni.getStorage({
					key: 'storage_key',
					success: function(res) {
						console.log(res.data);
					}
				});
			},
			User() {
				uni.navigateTo({
					url:'UserAgreement'
				})
			},
			my(){
				uni.reLaunch({
					url:'My'
				})
			},
			Privacy(){
				uni.navigateTo({
					url:'PrivacyPolicy'
				})
			},
			checkInputPhone: function() {
				if (this.phone === '') {
					uni.showToast({
						title: '手机号码不能为空',
						duration: 2000,
						icon: 'none'
					});
					return false;
				}
				let regs = /^((13[0-9])|(17[0-1,6-8])|(15[^4,\\D])|(18[0-9]))\d{8}$/;
				if (this.phone.length != 11) {
					uni.showToast({
						title: '手机号码不对',
						duration: 2000,
						icon: 'none'
					});
					return false;
				} else {
					if (!regs.test(this.phone)) {
						uni.showToast({
							title: '手机格式非法',
							duration: 2000,
							icon: 'none'
						});
						return false;
					} else {
						return true;
					}
				}
			}
		}
	}
</script>

<style>
	.banter {
		width: 300rpx;
		height: 300rpx;
		position: relative;
		top: 200rpx;
		left: 50%;
		margin-left: -150rpx;
	}

	.butde {
		font-size: 50rpx;
		position: relative;
		top: 8rpx;
		color: #E1E4E9;
	}

	.bold {
		display: flex;
		position: relative;
		width: 90%;
		margin-left: 5%;
		top: 300rpx;
		border-bottom: 1rpx solid #E4E5E7;
		height: 100rpx;
	}

	.boot {
		margin-top: 20rpx;
		margin-left: 10rpx;
		width: 65%;
	}

	.botteer {
		width: 200rpx;
		height: 70rpx;
		line-height: 70rpx;
		text-align: center;
		border-radius: 10rpx;
		margin: 5rpx 0 0 10rpx;
		border: #007EC5 solid 1rpx;
		color: #007EC5;
	}

	.box1 {
		width: 72%;
		margin-left: 14%;
		height: 90rpx;
		background-color: #0956A8;
		border-radius: 20rpx;
		line-height: 90rpx;
		text-align: center;
		color: #fff;
		position: relative;
		top: 400rpx;
	}

	.box5 {
		position: relative;
		top: 420rpx;
		font-size: 20rpx;
		width: 71%;
		margin-left: 16%;
	}

	.bue {
		color: #007EC5;
	}
</style>
